#include<bits/stdc++.h>
using namespace std;
priority_queue<int , vector<int> , greater<int> >heap;
int n , ans;
int main(){
	freopen("fruit.in" , "r" , stdin);
	freopen("fruit.out" , "w" , stdout);
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		int x;
		cin >> x;
		heap.push(x);
	}
	while(heap.size() > 1){
		int t = heap.top();
		heap.pop();
		t = t + heap.top();
		heap.pop();
		ans += t;
		heap.push(t);
	}
	cout << ans << endl;
	return 0;
}